<?php
namespace app\mouth\model;
use think\Model;
use think\Db;
class CircleNewsModel extends Model{
    public static function index($id){
       $news['fabulous'] = Db::name('circle_fabulous')->where('p_id',$id)->where('date',1)->count();//新增点赞人数
        $news['follow'] = Db::name('circle_follow')->where('main_id',$id)->where('date',1)->count();//新增关注人数
        $news['comment'] = Db::name('circle_comment')->where('p_id',$id)->where('date',1)->count();//新增评论人数
        $chat = Db::name('circle_chat')->where('user_id',$id)->column('id');//聊天
        if (empty($chat)){
            return $news;
        }
        $id = implode(',',$chat);
        $news['chat'] = Db::name('circle_sort_column')->where('chat_id',$id)->order('time desc')->select();//聊天室
        return $news;
    }
    public static function praisePeople($id,$state){
        if ($state == 1){
           Db::name('circle_fabulous')->where('p_id',$id)->update(['date'=>2]);
           $date = Db::name('circle_fabulous')->where('p_id',$id)->select();
        } elseif($state ==2){
            Db::name('circle_follow')->where('main_id',$id)->update(['date'=>2]);
            $date = Db::name('circle_follow')->where('main_id',$id)->select();
        }else{
            Db::name('circle_comment')->where('p_id',$id)->update(['date'=>2]);
            $date = Db::name('circle_comment')->where('p_id',$id)->select();
        }
        return $date;
    }
    public static function newFollow(){

    }
}